import { createStore } from 'vuex'

export default createStore({
  state: {
    user: {
      avatar: localStorage.getItem('userAvatar') || '',
    },
    nickname: {
      nickname: localStorage.getItem('userNickname') || '',
    },
    info: {
      info: localStorage.getItem('userInfo') || '',
    }
  },
  mutations: {
    updateUserAvatar(state, payload) {
      state.user.avatar = payload;
    },
    updateUserNickname(state, payload) {
      state.user.nickname = payload;
    },
    updateUserInfo(state, payload) {
      state.user.info = payload;
    }
  },
  actions: {
    updateAvatar({ commit }, payload) {
      commit('updateUserAvatar', payload);
    },
    updateNickname({ commit }, payload) {
      commit('updateUserNickname', payload);
    },
    updateInfo({ commit }, payload) {
      commit('updateUserInfo', payload);
    }
  },
  getters: {
    getUserAvatar: (state) => state.user.avatar,
    getUserNickname: (state) => state.user.nickname,
    getUserInfo: (state) => state.user.info,
  }
})